package com.cat.bitOperation;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/maximum-xor-for-each-query/description/
 * @create 2025/8/20 10:07
 * @since JDK17
 */

public class Solution04 {
    public int[] getMaximumXor(int[] nums, int maximumBit) {
        int n = nums.length, xor = 0, h = (1 << maximumBit) - 1;
        int[] ans = new int[n];
        for (int i = 0; i < n; i++) {
            xor ^= nums[i];
        }

        for (int i = 0; i < n; i++) {
            ans[i] = xor ^ h;
            xor ^= nums[n - i - 1];
        }
        return ans;
    }
}
